package com.ethink.platform.controller.system;

import com.ethink.framework.common.web.BaseController;
import com.ethink.framework.common.web.context.SPRequestContextHolder;
import com.ethink.framework.common.web.response.CommonResponse;
import com.ethink.system.api.SystemUserFacade;
import com.ethink.system.api.info.SystemUserSessionInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author default
 * @date 2022-09-26
 */
@Tag(name = "SystemUserSessionController", description = "系统用户会话管理 Controller")
@RestController
@Slf4j
@RequestMapping("platform-server/v1/system-service")
public class SystemUserSessionController extends BaseController {

    @Autowired
    private SystemUserFacade systemUserFacade;

    @Operation(summary = "获取用户信息")
    @GetMapping("/systemUserSession/get")
    public CommonResponse<SystemUserSessionInfo> getSystemUserSession() {
        String loginName = SPRequestContextHolder.getCurrentSystemUserLoginName();
        return succeedWith(systemUserFacade.getSystemUserSession(loginName));
    }

    @Operation(summary = "登录by accessToken")
    @PostMapping("/systemUserSession/loginByAccessToken")
    public CommonResponse<SystemUserSessionInfo> loginByAccessToken(String token) {
        return succeedWith(systemUserFacade.loginByAccessToken(token));
    }

}